package com.wly.utils;

import java.util.Iterator;

import com.wly.datapool.heropool.hero.BaseHero;
import com.wly.datapool.playerpool.BasePlayer;
import com.wly.datapool.playerpool.Player;
import com.wly.define.IDZoneDefine;
import com.wly.define.TalentDefine;
import com.wly.gpb.Schero;
import com.wly.gpb.Schero.Hero;
import com.wly.gpb.Scplayer.Player.Builder;
import com.wly.packet.SCPlayer;

public class DataFactory
{
	static public BasePlayer createNewPlayer(String name)
	{
		com.wly.datapool.heropool.hero.Hero hero;
		BasePlayer player = new Player(name);
		
		player.getHeroList().add(createNewHero(player, 0));
		player.getHeroList().add(createNewHero(player, 1));
		player.getHeroList().add(createNewHero(player, 2));
		player.getHeroList().add(createNewHero(player, 3));
		player.getHeroList().add(createNewHero(player, 4));
		return player;
	}
	
	static public com.wly.datapool.heropool.hero.Hero createNewHero(BasePlayer player, int heroId)
	{
		com.wly.datapool.heropool.hero.Hero hero = new com.wly.datapool.heropool.hero.Hero(heroId);
		hero.playerId = player.getPlayerId();
		return hero;
	}
	
	static public SCPlayer builderPlayerMessageByPlayer(BasePlayer player)
	{
		SCPlayer scPlayer = new SCPlayer();
		Builder bulder = (Builder)scPlayer.getBuilder();
		
		bulder.setName(player.getName());
		bulder.setId(player.getPlayerId());
		bulder.setMapid(player.getMapId());
		bulder.setPosx(player.getPosY());
		bulder.setPosy(player.getPosY());
		
		Iterator it = player.getHeroList().iterator();
		while(it.hasNext())
		{
			bulder.addHeros(builderHeroMessage((BaseHero)it.next()));
		}
		scPlayer.build();
		return scPlayer;
	}
	
	static public Hero builderHeroMessage(BaseHero hero)
	{
		com.wly.gpb.Schero.Hero.Builder builder = Hero.newBuilder();
		builder.setExp(hero.getExp());
		builder.setId(hero.getHeroId());
		builder.setLevel(hero.getLevel());
		builder.setName(hero.getName());
		//builder.setSoldierNum(hero.getSoldierNum());
		builder.setSoldierMaxNum(hero.getSoldierMaxNum());
		
		builder.setAttackTalent(hero.getTalentByType(TalentDefine.ATTACK_TALENT));
		builder.setSpeedTalent(hero.getTalentByType(TalentDefine.SPEED_TALENT));
		builder.setTenacityTalent(hero.getTalentByType(TalentDefine.TENACITY_TALENT));
		builder.setStrengthTalent(hero.getTalentByType(TalentDefine.STRENGTH_TALENT));
		builder.setLeaderTalent(hero.getTalentByType(TalentDefine.LEADER_TALENT));
		return builder.build();
	}
}
